﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.PriceManageViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Quản lý giá
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
   
    <script type="text/javascript">
    $(function () {
        $("#StartDateSearch").datepicker({ dateFormat: 'dd/mm/yy' });
        $("#EndDateSearch").datepicker({ dateFormat: 'dd/mm/yy' });
    });
	</script>
    <script type="text/javascript">
        function SaveStatus(dropDownList, id) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;
            actionChangeStatus(selects, id);
        }
        function actionChangeStatus(values, id) {
            var url = '<%=Url.Action("ChangeStatusPriceManage","Stock")%>' + '/' + id + '/' + values;
            $.getJSON(url, function (outStr) {
                $('#statusID' + id).val(outStr);
            });
        }
     </script>
    <% using (Html.BeginForm("PriceManage", "Stock", FormMethod.Post, new { id = "sendFileForm", enctype = "multipart/form-data" }))
   {%>
    <div class="clear"></div>
    <div class="column full">
    <div class="box ">
		<h2 class="box-header">	Price Manage : <%=Model.Product.ProductName %></h2>
		<div class="box-content">
                    
                    <div id="grid">	
                               	 <div style="margin: 5px; float:right;"><%= Html.ActionLink("Tạo giá mới", "CreatePrice", new { id = Model.Product.ProductID }, new { @Class = "button themed" })%></div>	    						               
				                <table class="display" id="tabledata" >
                                <thead>
					                <tr>
						                <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "PriceValue") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "PriceValue")%>">
								                Giá</a>
                                        </th>
                                        
                                        <th>
                                            <%--<a href="#" class="<%= StockController.GetGridThClass(ViewData, "Unit") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "Unit")%>">
								                </a>--%>
                                                Tiền tệ
                                        </th>	
                                            				               
						                <th>
							                <a href="#" class="<%= StockController.GetGridThClass(ViewData, "StartDate") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "StartDate")%>">
								                Ngày bắt đầu</a>
						                </th>
						
						                <th>
							                <a href="#" class="<%= StockController.GetGridThClass(ViewData, "EndDate") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "EndDate")%>">
								                Ngày hết hạn</a>
						                </th>											                

                                        <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "Satus") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "Satus")%>">
								                Trạng thái</a>
                                        </th>
                                                                              
                                        <th colspan="2"></th>                                       
					                </tr>
                                   <%-- <tr>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td colspan="2">
                                             
                                        </td>
                                    </tr>--%>
                                    <tr>
                                        <td>
                                            <%=Html.TextBoxFor(m => m.ValueSearch, new { @class = "form-field hafl", @maxlength = "50" })%>
                                        </td>
                                        <td></td>
                                        <td>
                                            From: <%=Html.TextBoxFor(m=>m.StartDateSearch,new { @class = "form-field datepicker"}) %>
                                        </td>
                                        <td>
                                            To: <%=Html.TextBoxFor(m=>m.EndDateSearch,new { @class = "form-field datepicker"}) %>
                                        </td>
                                        <td>
                                            <%
                                                List<SelectListItem> statusSearch = new List<SelectListItem>();
                                                statusSearch.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{ Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>

                                                <%=Html.DropDownListFor(m => m.StatusSearch, statusSearch)%> 
                                        </td>
                                        <td colspan="2">
                                            <input type="submit" value="Tìm kiếm" class="button themed"/>
                                        </td>
                                    </tr>
                                </thead>
                                <% if (Model.ProductPriceList.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                              Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% } else { %>
                                <tbody>
					                <% foreach (var item in Model.ProductPriceList) { %>
				    
						                <tr>						                
							                <td>
								                <%= Html.Encode(item.PriceValue) %>
							                </td>
							
                                            <td>
                                                <%
                                                   string CurrencyCode = "";
                                                   if (item.CurrencyID != null)
                                                   {
                                                       var currency = StockModel.GetCurrencyByID((int)item.CurrencyID);
                                                       CurrencyCode = currency.CurrencyCode;
                                                   }
                                                %>
                                                <%=CurrencyCode %>
                                            </td> 
                                            
							                <td>
								                <%= Html.Encode(String.Format("{0:dd/MM/yyyy}",(DateTime)item.StartDate)) %>
							                </td>
														                
                                            <td>
                                               <%= Html.Encode(String.Format("{0:dd/MM/yyyy}", (DateTime)item.EndDate))%>
                                            </td>
                                            
                                            <td>
                                               <%
                                                    bool newStatus=false;
                                                    if (item.Satus == 0)
                                                    {
                                                        newStatus=true;
                                                    }
                                                    else if (item.Satus == 1)
                                                    {
                                                        newStatus=false;
                                                    }
                                                %>
                                                <%
                                                List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                statusDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=newStatus, Text = "Hiển thị", Value = "1" },
                                                new SelectListItem{Selected=newStatus, Text = "Không hiển thị", Value = "0" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("statusID" + item.PriceID, statusDrop, new { onchange = "SaveStatus(this," + item.PriceID + ")" })%>
                                            </td>
                                            
                                            <td>
                                                <%= Html.ActionLink("Cập nhật", "EditPrice", new { id = item.PriceID })%>
                                            </td>
                                            <td>
                                                <%
                                                    string returnUrl = Request.Url.ToString();
                                                 %>
                                                <span class="button white"><%= Html.ActionLink(" ", "DeletePrice", "Stock", new { id = item.PriceID, returnUrl = returnUrl }, new { @class = "icon_single cancel", style = "color:#cc0000;", onclick = "return confirm('Delete Price:" + item.PriceValue + " ?');"})%></span>
                                            </td>
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
			                <!-- data -->
                                <% if (Model.ProductPriceList.Count() > 0) { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>
		                
	                </div>  <!-- grid -->	
                
               
	    </div>
	</div>
    <div class="clear"></div>
    </div>    
<% } %>

</asp:Content>
